import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import {ComponentsPropsType} from '../../components/QuestionComponents'

// 定义组件的元素类型
export type ComponentsType= {
    fe_id : string
    title : string
    type : string
    props : ComponentsPropsType
}

export type ComponentStateType = {
    componentsList : ComponentsType[] // 组件列表，以组件为元素类型的数组
}

const INIT_DATA : ComponentStateType = {
    componentsList : [],
    // 可扩展
}

export const componentSlice = createSlice({
    name : 'components',
    initialState : INIT_DATA,
    reducers : {
        // 重制所有组件
        resetComponents : (state:ComponentStateType,action :PayloadAction<ComponentStateType>)=>{
            return action.payload
        }
    }
})

export const {resetComponents} = componentSlice.actions
export default componentSlice.reducer
